using System;
using Orm;

namespace ormsamples {
	public class RetrieveAndUpdatePetShopData {
		private void RetrieveAndUpdateData() {
			PersistentTransaction t = petshop.PetShopPersistentManager.Instance().GetSession().BeginTransaction();
			try {
				petshop.Pet lpetshopPet = petshop.PetFactory.LoadPetByQuery(null, null);
				// Update the properties of the persistent object
				lpetshopPet.Save();
				petshop.Transaction lpetshopTransaction = petshop.TransactionFactory.LoadTransactionByQuery(null, null);
				// Update the properties of the persistent object
				lpetshopTransaction.Save();
				petshop.Customer lpetshopCustomer = petshop.CustomerFactory.LoadCustomerByQuery(null, null);
				// Update the properties of the persistent object
				lpetshopCustomer.Save();
				petshop.Staff lpetshopStaff = petshop.StaffFactory.LoadStaffByQuery(null, null);
				// Update the properties of the persistent object
				lpetshopStaff.Save();
				t.Commit();
			}
			catch(Exception e) {
				t.RollBack();
				Console.WriteLine(e);
			}
			
		}
		
		public void RetrieveByCriteria() {
			System.Console.WriteLine("Retrieving Pet by PetCriteria");
			petshop.PetCriteria lpetshopPetCriteria = new petshop.PetCriteria ();
			// Please uncomment the follow line and fill in parameter(s)
			//lpetshopPetCriteria.id.Eq();
			System.Console.WriteLine( lpetshopPetCriteria.UniquePet());
			
			System.Console.WriteLine("Retrieving Transaction by TransactionCriteria");
			petshop.TransactionCriteria lpetshopTransactionCriteria = new petshop.TransactionCriteria ();
			// Please uncomment the follow line and fill in parameter(s)
			//lpetshopTransactionCriteria.ID.Eq();
			System.Console.WriteLine( lpetshopTransactionCriteria.UniqueTransaction());
			
			System.Console.WriteLine("Retrieving Customer by CustomerCriteria");
			petshop.CustomerCriteria lpetshopCustomerCriteria = new petshop.CustomerCriteria ();
			// Please uncomment the follow line and fill in parameter(s)
			//lpetshopCustomerCriteria.ID.Eq();
			System.Console.WriteLine( lpetshopCustomerCriteria.UniqueCustomer());
			
			System.Console.WriteLine("Retrieving Staff by StaffCriteria");
			petshop.StaffCriteria lpetshopStaffCriteria = new petshop.StaffCriteria ();
			// Please uncomment the follow line and fill in parameter(s)
			//lpetshopStaffCriteria.ID.Eq();
			System.Console.WriteLine( lpetshopStaffCriteria.UniqueStaff());
			
		}
		
		
		[STAThread]
		public static void Main(string[] args) {
			RetrieveAndUpdatePetShopData retrieveAndUpdatePetShopData = new RetrieveAndUpdatePetShopData();
			try {
				retrieveAndUpdatePetShopData.RetrieveAndUpdateData();
//				retrieveAndUpdatePetShopData.RetrieveByCriteria();
			}
			finally {
				petshop.PetShopPersistentManager.Instance().DisposePersistentManager();
			}
			
		}
		
	}
}

